package com.dangf.app.launcher.utils

import android.view.View
import android.view.animation.AlphaAnimation
import android.view.animation.Animation

/**
 * Created by hais1992 on 2017/9/6/006.
 */
class AnimUtil(val view: View) {
    private val animShow by lazy {
        val x = AlphaAnimation(0.0f, 1.0f)
        x.duration = 500
        x.setAnimationListener(object : Animation.AnimationListener {
            override fun onAnimationRepeat(p0: Animation?) {}
            override fun onAnimationEnd(p0: Animation?) = startAnim(false)
            override fun onAnimationStart(p0: Animation?) {}
        })
        x
    }

    private val animHide by lazy {
        val o = AlphaAnimation(1.0f, 0.0f)
        o.duration = 500
        o.setAnimationListener(object : Animation.AnimationListener {
            override fun onAnimationRepeat(p0: Animation?) {}
            override fun onAnimationEnd(p0: Animation?) = startAnim(true)
            override fun onAnimationStart(p0: Animation?) {}
        })
        o
    }


    fun startAnim(isShow: Boolean = false) {
        if (isShow) view.startAnimation(animShow)
        else view.startAnimation(animHide)
    }

}